package demo.practice.double_pointer;

public class P647 {

    public static void main(String[] args) {
        P647 p647= new P647();
        p647.countSubstrings("abc");
    }
    public int countSubstrings(String s) {
        char[] chars = s.toCharArray();
        int range = chars.length - 1;

        int res = 0;
        for (int i = 1; i <= range; i++) { //j是跨度
            for (int j = 0; j + i < chars.length; j++) {
                if (check(chars, j, j + i)) {
                    res++;
                }
            }
        }

        return res + chars.length;

    }

    public boolean check(char[] chars, int i, int j) {
        while (i < j) {
            if (chars[i] != chars[j]) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
}
